import type {
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage,
  ConsultOrderPreData,
  ConsultOrderPreParams,
  DepList,
  DoctorPage,
  FollowType,
  Image,
  KnowledgePage,
  KnowledgeType,
  PartialConsult
} from '@/types/consult'
import { request } from '@/utils/request'

// 获取文章列表
export const getKnowledgeList = (type: KnowledgeType, current: number, pageSize: number) =>
  request<KnowledgePage>('/patient/home/knowledge', 'get', { type, current, pageSize })

//   获取关注医生
export const getDoctorList = (current: number, pageSize: number) => {
  return request<DoctorPage>('/home/page/doc', 'get', { current, pageSize })
}

// 关注医生、文章
export const followOrUnfollow = (id: string, type: FollowType = 'doc') => {
  return request('/like', 'post', { id, type })
}

// 获取科室
export const getAllDep = () => request<DepList>('/dep/all')

// 上传图片
export const uploadImage = (fileData: File) => {
  const fd = new FormData()
  fd.append('file', fileData)
  return request<Image>('/upload', 'post', fd)
}

// 拉取预支付订单信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

// 生成订单
export const createConsultOrder = (data: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', data)

// 获取支付地址  0 是微信  1 支付宝
export const getConsultOrderPayUrl = (params: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)

// 获取订单详情
export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })

// 查看处方
export const getPrescriptionPic = (id: string) =>
  request<{ url: string }>(`/patient/consult/prescription/${id}`)

// 评价问诊
export const evaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request<{ id: string }>('/patient/order/evaluate', 'POST', data)

export const getConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)
